*see my notes at the bottom
clear
infile using "patterson.dct"

for num 3/5: rename ideo_X ideo_s_X 
*date
tab day_4 month_4 
tab day_5 
 recode Carter_* Ford_* (0 8/9=.)

*vote
 recode vote_* (1 =0) (2 =1) (3/9=.)  // ASK GABE: IS THIS CHANGE CORRECT?  PREVIOUSLY 3/7 CODED AS 0.5
*favorability towards Carter and Ford
tab  Carter_4
for num 1/5: g cvf_X = (Carter_X-Ford_X+6)/12
for num 1/5: g thermc_X =((1 -cvf_X)*6) + 1
sum cvf_*

*PID
recode PID_* (0=.) (8/9=.)
foreach i in PID {
	for num 1/5: replace `i'_X = (`i'_X-1)/6
}
for num 1/5: g therm_X =((PID_X)*6) + 1

* ideology
recode ideo_s_* (0=.) (8/9=.)
foreach i in ideo {
	for num 3/5: replace `i'_s_X = (`i'_s_X-1)/6
}
tab1 ideo_c_* ideo_f_* ideo_d_* ideo_r_*
foreach i in ideo {
  for num 4/5: g k_`i'_X = `i'_c_X <`i'_f_X & `i'_c_X!=8 & `i'_f_X!= 8 if `i'_c_X>0 & `i'_f_X>0 & `i'_c_X<. & `i'_f_X<. & `i'_c_X!=9 & `i'_f_X!= 9
  for num 4/5: g kp_`i'_X =`i'_d_X <`i'_r_X & `i'_d_X!=8 & `i'_r_X!= 8 if `i'_c_X>0 & `i'_r_X>0 & `i'_d_X<. & `i'_r_X<. & `i'_d_X!=9 & `i'_r_X!= 9 
}
sum k_ideo_* kp_ideo_* 

*LA
tab id
g LA = id >200

 tabulate jobs_5 jobs_c_5,mis
 
*RECOGNITION OF PRIMARY CANDIDATE NAMES
foreach i in Wall Bayh Shri Jack Bent Hump Chur Harr Kenn Udal Cart Shap Musk Ford Math Bake Perc Reag Rock {
for num 1: g gk_`i'_X = `i'_k_X
}

foreach i in Wall Bayh Shri Jack Bent Hump Chur Harr Kenn Udal Cart Shap Musk Ford Math Bake Perc Reag Rock {
recode gk_`i'_1 (0=.) (1=0) (2=1) (3=1) (9=.) 
}

*g gk_cand = gk_Wall_1 + gk_Bayh_1 + gk_Shri_1 + gk_Jack_1 + gk_Bent_1 + gk_Hump_1 + gk_Chur_1 + gk_Harr_1 + gk_Kenn_1 + ///
*gk_Udal_1 + gk_Cart_1 + gk_Shap_1 + gk_Musk_1 + gk_Ford_1 + gk_Math_1 + gk_Bake_1 + gk_Perc_1 + gk_Reag_1 + gk_Rock_1
sum gk_Chur_1 gk_Bayh_1 gk_Shri_1  gk_Jack_1 gk_Harr_1 gk_Udal_1 gk_Shap_1 gk_Math_1 gk_Bake_1 gk_Perc_1 


								
*KNOWLEDGE OF CANDIDATE POSITIONS
*check that Carter is always to the left of Ford-scales are balanced, Carter not always smaller
  for any jobs int price def spd tax abr jail bus: sum X_c_4 X_f_4 if X_c_4>0 & X_f_4>0 & X_c_4<8 & X_f_4<8 
  for any jobs int price def spd tax abr jail bus: sum X_c_5 X_f_5 if X_c_5>0 & X_f_5>0 & X_c_5<8 & X_f_5<8 
*for issues where Carter should have a smaller value then Ford on the scale
foreach i in jobs price spd {
  for num 3/5: g k_`i'_X = `i'_c_X <`i'_f_X & `i'_c_X!=8 & `i'_f_X!= 8  & `i'_c_X!=9 & `i'_f_X!= 9 if `i'_c_X>0 & `i'_f_X>0 & `i'_c_X<. & `i'_f_X<.
  for num 3/5: g kp_`i'_X =`i'_d_X <`i'_r_X & `i'_d_X!=8 & `i'_r_X!= 8  & `i'_d_X!=9 & `i'_r_X!= 9 if `i'_d_X>0 & `i'_r_X>0 & `i'_d_X<. & `i'_r_X<. 
}
*for issues where Carter should have a smaller value then Ford on the scale
foreach i in abr bus {
  for num 4/5: g k_`i'_X = `i'_c_X <`i'_f_X & `i'_c_X!=8 & `i'_f_X!= 8  & `i'_c_X!=9 & `i'_f_X!= 9 if `i'_c_X>0 & `i'_f_X>0 & `i'_c_X<. & `i'_f_X<.
  for num 4/5: g kp_`i'_X =`i'_d_X <`i'_r_X & `i'_d_X!=8 & `i'_r_X!= 8  & `i'_d_X!=9 & `i'_r_X!= 9 if `i'_d_X>0 & `i'_r_X>0 & `i'_d_X<. & `i'_r_X<. 
}
*for issues where Carter should have a smaller value then Ford on the scale
foreach i in    tax  {
  for num 3/5: g k_`i'_X  = `i'_c_X >`i'_f_X & `i'_c_X!=8 & `i'_f_X!= 8 & `i'_c_X!=9 & `i'_f_X!= 9 if `i'_c_X>0 & `i'_f_X>0 & `i'_c_X<. & `i'_f_X<.
  for num 3/5: g kp_`i'_X = `i'_d_X >`i'_r_X & `i'_d_X!=8 & `i'_r_X!= 8 & `i'_d_X!=9 & `i'_r_X!= 9 if `i'_d_X>0 & `i'_r_X>0 & `i'_d_X<. & `i'_r_X<. 
}
foreach i in  int def jail {
  for num 4/5: g k_`i'_X  = `i'_c_X >`i'_f_X & `i'_c_X!=8 & `i'_f_X!= 8 & `i'_c_X!=9 & `i'_f_X!= 9 if `i'_c_X>0 & `i'_f_X>0 & `i'_c_X<. & `i'_f_X<.
  for num 4/5: g kp_`i'_X = `i'_d_X >`i'_r_X & `i'_d_X!=8 & `i'_r_X!= 8 & `i'_d_X!=9 & `i'_r_X!= 9 if `i'_d_X>0 & `i'_r_X>0 & `i'_d_X<. & `i'_r_X<. 
}
*check coding: abortion and busing look too low to be useful, barely above 25% which would be chance (without DK responses)
sum k_*_4 k_*_5
sum kp_*_4 kp_*_5
tab1 jobs_1 jobs_*_1 
*create knowledge of position scale *without* abortion and busing
*kb - knowledge growth - only one point if you get all four placements correct (candidates and parties in both waves)
  for any jobs int price def spd tax jail: g kb_X = k_X_4 == 1 & kp_X_4 == 1 & k_X_5 == 1 & kp_X_5 == 1 if k_X_4 != . & kp_X_4 != . & k_X_5 != . & kp_X_5 != . 
  for any jobs int price def spd tax jail: g k_X = k_X_4 == 1 & k_X_5 == 1  if k_X_4 != . & k_X_5 != .  
  for any jobs int price def spd tax jail: g kp_X = kp_X_4 == 1 & kp_X_5 == 1 if kp_X_4 != . & kp_X_5 != . 
  sum kb_*
  g kb = (kb_jobs + kb_int + kb_price + kb_def + kb_spd + kb_tax + kb_jail)/7
  g k = (k_jobs + k_int + k_price + k_def + k_spd + k_tax + k_jail)/7
  g kp = (kp_jobs + kp_int + kp_price + kp_def + kp_spd + kp_tax + kp_jail)/7
  g k_kp = (k +kp)/2

for any jobs int price def spd tax jail: g k_4_X = k_X_4 == 1 if k_X_4 != .
g k_4 = (k_4_jobs + k_4_int + k_4_price + k_4_def + k_4_spd + k_4_tax + k_4_jail)/7
for any jobs int price def spd tax jail: g k_5_X = k_X_5 == 1 if k_X_5 != .
g k_5 = (k_5_jobs + k_5_int + k_5_price + k_5_def + k_5_spd + k_5_tax + k_5_jail)/7


*Jobs knowledge earlier waves (
tab1 jobs_d_* jobs_r_*
foreach i in jobs   {
  for num 1 : g kp_`i'_X =`i'_d_X <`i'_r_X & `i'_d_X!=8 & `i'_r_X!= 8 & `i'_d_X!=9 & `i'_r_X!= 9 if `i'_c_X>0 & `i'_r_X>0 & `i'_d_X<. & `i'_r_X<.
}

 
* Two level knowledge scale
g k2 = 1 if k > .5
replace k2 = 0 if k <= .5 
replace k2 = . if k > 1

* Three-level knowledge scale
g k3 = 1 if k > .7
replace k3 = 0.5 if k <= .7 & k >=.3
replace k3 = 0 if k < 0.3  
replace k3 = . if k > 1

* Two level knowledge scale for wave 5
g k_5_2 = 1 if k_5 > .5
replace k_5_2 = 0 if k_5 <= .5 
replace k_5_2 = . if k_5 > 1

* Three-level knowledge scale for wave 5
g k_5_3 = 1 if k_5 > .7
replace k_5_3 = 0.5 if k_5 <= .7 & k_5 >=.3
replace k_5_3 = 0 if k_5 < 0.3  
replace k_5_3 = . if k_5 > 1



*ISSUE SCALE  
*create ideology scales with seven items (excluding abortion and busing)
for any jobs int price def spd tax jail:sum X_4 X_5
foreach i in jobs price spd abr bus {
  for num 1/5: g r_`i'_X = (`i'_X-1)/6 if `i'_X>0 & `i'_X<8
}
*for issues where Carter should have a smaller value then Ford on the scale
foreach i in  int def tax jail {
  for num 1/5: g r_`i'_X = 1 -(`i'_X-1)/6 if `i'_X>0 & `i'_X<8
}

for num 4/5: corr r_*_X 
for num 4/5: sum r_*_X
for num 4/5: g issues_X = (r_jobs_X + r_int_X + r_price_X + r_def_X + r_spd_X + r_tax_X + r_jail_X)/7


*economic issues scale *I included the tax cut question but it doesn't correlate with the other items, has a factor loading of only 0.3176
for any jobs price spd : egen stde_X_4 =std(r_X_4)
for any jobs price spd : egen stde_X_5 =std(r_X_5)
for num 4/5:g kt_economic_X = k_jobs_X + k_price_X + k_spd_X
/*sum stde_*_4
corr stde_*_4
factor stde_*_4 , pcf
 predict  economic_45
factor  stde_*_5 , pcf
 predict  economic_5
*/
*general knowledge
 *couldn't find any interviewer rating of respondent knowledge/information in codebook
sum k_jail_4 kp_jail_4 k_def_4 kp_def_4 k_jail_4 kp_jail_4 k_int_4 kp_int_4  k_bus_4 kp_bus_4 
sum k_jail_5 kp_jail_5 k_def_5 kp_def_5 k_jail_5 kp_jail_5 k_int_5 kp_int_5  k_bus_5 kp_bus_5 
pwcorr k_jail_4 kp_jail_4 k_def_4 kp_def_4 k_jail_4 kp_jail_4 k_int_4 kp_int_4  k_bus_4 kp_bus_4 gk_Chur_1 gk_Bayh_1 gk_Shri_1  gk_Jack_1 gk_Harr_1 gk_Udal_1 gk_Shap_1 gk_Math_1 gk_Bake_1 gk_Perc_1 
egen gk = rowtotal( k_jail_5 kp_jail_5 k_def_5 kp_def_5 k_jail_5 kp_jail_5 k_int_5 kp_int_5  k_bus_5 kp_bus_5 k_jail_4 kp_jail_4 k_def_4 kp_def_4 k_jail_4 kp_jail_4 k_int_4 kp_int_4  k_bus_4 kp_bus_4  gk_Chur_1 gk_Bayh_1 gk_Shri_1  gk_Jack_1 gk_Harr_1 gk_Udal_1 gk_Shap_1 gk_Math_1 gk_Bake_1 gk_Perc_1 )
*alpha k_jail_5 kp_jail_5 k_def_5 kp_def_5 k_jail_5 kp_jail_5 k_int_5 kp_int_5  k_bus_5 kp_bus_5 k_jail_4 kp_jail_4 k_def_4 kp_def_4 k_jail_4 kp_jail_4 k_int_4 kp_int_4  k_bus_4 kp_bus_4  gk_Chur_1 gk_Bayh_1 gk_Shri_1  gk_Jack_1 gk_Harr_1 gk_Udal_1 gk_Shap_1 gk_Math_1 gk_Bake_1 gk_Perc_1 

egen not_missing_gk = rownonmiss( k_jail_5 kp_jail_5 k_def_5 kp_def_5 k_jail_5 kp_jail_5 k_int_5 kp_int_5  k_bus_5 kp_bus_5 k_jail_4 kp_jail_4 k_def_4 kp_def_4 k_jail_4 kp_jail_4 k_int_4 kp_int_4  k_bus_4 kp_bus_4 gk_Chur_1 gk_Bayh_1 gk_Shri_1  gk_Jack_1 gk_Harr_1 gk_Udal_1 gk_Shap_1 gk_Math_1 gk_Bake_1 gk_Perc_1 )
tabulate not_missing_gk
replace gk = . if not_missing_gk<6
tab gk
*alpha k_jail_4 kp_jail_4 k_def_4 kp_def_4 k_jail_4 kp_jail_4 k_int_4 kp_int_4  k_bus_4 kp_bus_4 gk_Chur_1 gk_Bayh_1 gk_Shri_1  gk_Jack_1 gk_Harr_1 gk_Udal_1 gk_Shap_1 gk_Math_1 gk_Bake_1 gk_Perc_1 
